Skip to content

Add globals and callback handling#120

Merged
catilac merged 1 commit intoprocessing:mainfrom
tychedelia:globals-cbs
Apr 22, 2026
Merged

Add globals and callback handling#120
catilac merged 1 commit intoprocessing:mainfrom
tychedelia:globals-cbs

Conversation

@tychedelia
Copy link
Copy Markdown
Member

In Processing, globals and callbacks like width, height, mousePressed, etc. are members of the containing PApplet that the user's sketch runs in. This means that inside the user's draw function, the user can simply write width due to the elision of the this receiver in Java. Further, the draw loop can delegate callbacks to overrides on the user's PApplet.

In Python, this is problematic. For stylistic reasons, we do not want to have draw/setup require accepting a self receiver, as this would require writing self.width etc. anywhere the user wishes to access some Processing state. As such, in Python, we instead do a bit of magic in order make some global variables provide the same semantics as Processing.

This PR provides the following related changes to help support this:

  1. Adds a pattern around global variable updates to avoid overwriting user variables that may shadow our variable's names.
  2. Support for importing our main module as an alias, i.e. import mewnala as mn where mn.width delegates to the underlying getter via __getattr__.
  3. Callback functionality, where we introspect the global ns for a user's function.
  4. Input support to enable knowing when to fire callbacks.
  5. Misc surface methods for retrieving surface state.
  6. A new monitor API object. We don't support monitor selection fully yet but will in the future.
  7. Cleanup for ipython/jupyter hooks to make sure the above work.

@tychedelia tychedelia requested a review from catilac April 21, 2026 08:22
Comment thread crates/processing_pyo3/mewnala/__init__.py
@catilac
Copy link
Copy Markdown
Contributor

catilac commented Apr 22, 2026

does this mean we don't have to declare global anymore?

Copy link
Copy Markdown
Contributor

@catilac catilac left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this worked for raph so approving :)

@catilac catilac merged commit 73b6fad into processing:main Apr 22, 2026
1 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants